<?php

//2008.8.28 lyx
function smarty_function_dateCalenderSale($params, &$smarty)
{
	$status = $params["state"];
	$currentDateToyyyymm = $params["currentDateToyyyymm"];
	$_dayRow = array("",31,28,31,30,31,30,31,31,30,31,30,31);
	$_weekRow = array("jp"=>array("日","月","火","水","木","金","土"),
						     "zh"=>array("日","一","二","三","四","五","六"),
	    				     "en"=>array("SUN","MON","TUE","WEN","SUR","FRI","SAT"));

	$datetype =	$params["datetype"];

	$base=new Module_base();
	$baseArr=$base->getAllData();

    $m_s_no = $params["m_s_no"];
    $sale = new Module_sale();
     
	$_strYear = "";
	$_strWeek = "";
	$_strDay = "";
	$_language = "jp";
	$_Year;
	$_Month;
	$_Day;
	//$currentDateToyyyymm = '2008-7';
	if ($currentDateToyyyymm == "")
	{
		$_Year = date("Y");
		$_Month = date("n");
	}
	else
	{
		/*
		$_Year  = date("Y",strtotime($currentDateToyyyymm));
    	$_Month = date("n",strtotime($currentDateToyyyymm));
    	*/
    	$_Year  = substr($currentDateToyyyymm,0,4);//date("Y",strtotime($currentDateToyyyymm));
		if(strlen($currentDateToyyyymm) == 7)
		{
			$_Month = substr($currentDateToyyyymm,5,2);//date("n",strtotime($currentDateToyyyymm));
		}
		else
		{
			$_Month = substr($currentDateToyyyymm,5,1);
		}
	}
	
	if ($Day == "") 
	{
		$_Day = date("d");
	}
	else 
	{
		$_Day = $Day;
	}
	if ((($_Year%4 == 0) && ($_Year%100!= 0)) || ($_Year%400==0)) $_dayRow[2]= 29;
	if($_language == "en")
	{
		$YYYYMM = $_Year."/".$_Month;
	}
	else
	{
		$YYYYMM = $_Year."年".$_Month."月";
	}
	
	$halfMonth = $_dayRow[$_Month] - 15;

	$_strYear.= " <tr><td align='left'><table border='0' cellspacing='0' cellpadding='0'>
                                      <tr>
                                        <td width='5'><img src='images/images/images/waku_01.gif' width='5' height='5' /></td>
                                        <td background='images/images/images/waku_02.gif'><img src='images/images/images/waku_02.gif' width='221' height='5' /></td>
                                        <td width='6'><img src='images/images/images/waku_03.gif' width='6' height='5' /></td>
                                      </tr>
                                      <tr>
                                        <td width='5' background='images/images/images/waku_04.gif'><img src='images/images/images/waku_04.gif' width='5' height='60' /></td>
                                        <td align='center' valign='middle' bgcolor='#CCCCCC'><table width='100%' border='0' cellpadding='5' cellspacing='1'>";
	$_strYear .= "<tr>\r\n"; 
    $_strYear .= "<td colspan='16' align='left' bgcolor='#FFFFFF' class='text02'><strong>".$YYYYMM."  ".$roomname."</strong></td>\r\n";
    $_strYear .= "</tr>\r\n";
    $_strWeek .= "<tr>\r\n";  
	for($i=1; $i <= 16; $i++) 
	{
		
		if($i == 16)
		{
			$_strWeek .= "<td width='25' align='center' valign='middle' bgcolor='#DDE3EC' class='text02 style5'>&nbsp;</td>\r\n";
		}
		else
		{
			$_strWeek .= "<td align='center' valign='middle' bgcolor='#DDE3EC' class='text02'>".$i."</td>\r\n"; 
		}
	}
	$_strWeek .= "</tr>\r\n";
	$_strWeek .= "<tr>\r\n";
	for($j=1;$j <=16;$j++)
	{
		$currentDateByWeek = date("w",strtotime($currentDateToyyyymm."-".$j));
		
		if($j == 16)
		{
			$_strWeek .="<td align='center' valign='middle' bgcolor='#FFFFFF' class='text02'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
		}
		else
		{
			if($currentDateByWeek == 6)
			{
				$_strWeek .= "<td height='40' align='center' valign='middle' bgcolor='#FFFFFF' class='text02 style6'>".$_weekRow[$_language][$currentDateByWeek]."</td>";
			}
			elseif($currentDateByWeek == 0)
			{
				$_strWeek .= "<td height='40' align='center' valign='middle' bgcolor='#FFFFFF' class='text02 style3'>".$_weekRow[$_language][$currentDateByWeek]."</td>";
			}
			else
			{
				$_strWeek .= "<td height='40' align='center' valign='middle' bgcolor='#FFFFFF' class='text02'>".$_weekRow[$_language][$currentDateByWeek]."</td>";
			}
		}	
	}
	$_strWeek .= "</tr>\r\n";
	$_strWeek .= "<tr>\r\n";
	for($j=1;$j <=16;$j++)
	{
		if($j == 16)
		{
			$_strWeek .= "<td height='40' align='center' valign='middle' bgcolor='#FFFFFF' class='text02 style6'>&nbsp;</td>";
		}
		else
		{
			$options = array();
			$re_date = date("Ymd",strtotime($_Year."-".$_Month."-".$j));
			
			for($k=1;$k<=$datetype;$k++)
		    {
		   	        $options[$k] = $k;
		   	}
			$_strWeek .= "<td height='40' align='center' valign='middle' bgcolor='#FFFFFF' class='text02'><select name='select".$m_s_no.$j."' style='width:50px; '>";
			
			for($i=1;$i <= $datetype; $i++)
			{
				
				$currentDateToyyyymm . $j; 
				
				$schedule = "0";
				if($sale->getMsschedule($re_date,$m_s_no) != "")
				{
					$schedule = $sale->getMsschedule($re_date,$m_s_no);
				}
			   $isPhone = $sale->isPhone($re_date,$m_s_no);
			    if($i == 1)
			    {
			    	if($schedule == "0")
			    	{
			    		if($isPhone == "m")
			    		{
			    	       $_strWeek .= "<option value='-2'>－</option><option value='0' selected>満室</option><option value='-1'>電話</option>";
			    		}
			    		else if($isPhone == "d")
			    		{
			    		    $_strWeek .= "<option value='-2'>－</option><option value='0'>満室</option><option value='-1' selected>電話</option>";
			    		}
			    		else
			    		{
			    			$_strWeek .= "<option value='-2' selected>－</option><option value='0'>満室</option><option value='-1'>電話</option>";
			    		}
			    	}
			    	else 
			    	{
			    		$_strWeek .= "<option value='-2' selected>－</option><option value='0'>満室</option><option value='-1'>電話</option>";
			    	}
			    }
				
				if($schedule == $options[$i])
				{
					$_strWeek .= "<option value=".$options[$i]." selected>".$options[$i]."室</option>";
				} 
				else
				{
					$_strWeek .= "<option value=".$options[$i].">".$options[$i]."室</option>";
				}
				
			}
			$_strWeek .="</select></td>";
		}
	}
	$_strWeek .= "</tr>\r\n";
	$_strWeek .= "<tr>\r\n";
	
	for($i = 16; $i <= $_dayRow[$_Month]; $i++)
	{
		$_strWeek .= "<td align='center' valign='middle' bgcolor='#DDE3EC' class='text02'>".$i."</td>";
	}
	if($_dayRow[$_Month] != 31)
   {
	if($_dayRow[$_Month] == 30)
	{
		
		$_strWeek .= "<td width='25' align='center' valign='middle' bgcolor='#DDE3EC' class='text02 style5'>&nbsp;</td>";
	}
	elseif($_dayRow[$_Month] == 29)
	{
		$_strWeek .= "<td width='25' align='center' valign='middle' bgcolor='#DDE3EC' class='text02 style5'>&nbsp;</td><td width='25' align='center' valign='middle' bgcolor='#DDE3EC' class='text02 style5'>&nbsp;</td>";
	}
	else
	{
		  
			$_strWeek .= "<td width='25' align='center' valign='middle' bgcolor='#DDE3EC' class='text02 style5'>&nbsp;</td><td width='25' align='center' valign='middle' bgcolor='#DDE3EC' class='text02 style5'>&nbsp;</td>
			              <td width='25' align='center' valign='middle' bgcolor='#DDE3EC' class='text02 style5'>&nbsp;</td>";
	}
	}
	$_strWeek .= "</tr>\r\n";
	$_strWeek .= "<tr>\r\n";
	for($j=16;$j <=$_dayRow[$_Month];$j++)
	{
	
		$currentDateByWeek = date("w",strtotime($currentDateToyyyymm."-".$j));
	
		
			if($currentDateByWeek == 6)
			{
				$_strWeek .= "<td height='40' align='center' valign='middle' bgcolor='#FFFFFF' class='text02 style6'>".$_weekRow[$_language][$currentDateByWeek]."</td>";
			}
			elseif($currentDateByWeek == 0)
			{
				$_strWeek .= "<td height='40' align='center' valign='middle' bgcolor='#FFFFFF' class='text02 style3'>".$_weekRow[$_language][$currentDateByWeek]."</td>";
			}
			else
			{
				$_strWeek .= "<td height='40' align='center' valign='middle' bgcolor='#FFFFFF' class='text02'>".$_weekRow[$_language][$currentDateByWeek]."</td>";
			}
	}
	if($_dayRow[$_Month] != 31)
   {
	if($_dayRow[$_Month] == 30)
	{
		$_strWeek .= "<td align='center' valign='middle' bgcolor='#FFFFFF' class='text02'>&nbsp;</td>";
	}
	elseif($_dayRow[$_Month] == 29)
	{
		$_strWeek .= "<td align='center' valign='middle' bgcolor='#FFFFFF' class='text02'>&nbsp;</td><td align='center' valign='middle' bgcolor='#FFFFFF' class='text02'>&nbsp;</td>";
	}
	else
	{
			$_strWeek .= "<td align='center' valign='middle' bgcolor='#FFFFFF' class='text02'>&nbsp;</td><td align='center' valign='middle' bgcolor='#FFFFFF' class='text02'>&nbsp;</td>
			               <td align='center' valign='middle' bgcolor='#FFFFFF' class='text02'>&nbsp;</td>";
	}
	}
	$_strWeek .= "</tr>\r\n";
	$_strWeek .= "<tr>\r\n";
    for($j=16;$j <=$_dayRow[$_Month];$j++)
	{
			$_strWeek .= "<td height='40' align='center' valign='middle' bgcolor='#FFFFFF' class='text02'><select name='select".$m_s_no.$j."' style='width:50px; '>";
			
			for($i=1;$i <= $datetype; $i++)
			{
				$currentDateToyyyymm . $j; 
				$re_date = date("Ymd",strtotime($_Year."-".$_Month."-".$j));
				$schedule = "0";
				if($sale->getMsschedule($re_date,$m_s_no) != "")
				{
					$schedule = $sale->getMsschedule($re_date,$m_s_no);
				}
                $isPhone = $sale->isPhone($re_date,$m_s_no);
				 if($i == 1)
			    {
			        if($schedule == "0")
			    	{
			    		if($isPhone == "m")
			    		{
			    	       $_strWeek .= "<option value='-2'>－</option><option value='0' selected>満室</option><option value='-1'>電話</option>";
			    		}
			    		else if($isPhone == "d")
			    		{
			    		    $_strWeek .= "<option value='-2'>－</option><option value='0'>満室</option><option value='-1' selected>電話</option>";
			    		}
			    		else
			    		{
			    			$_strWeek .= "<option value='-2' selected>－</option><option value='0'>満室</option><option value='-1'>電話</option>";
			    		}
			    	}
			    	else 
			    	{
			    		$_strWeek .= "<option value='-2' selected>－</option><option value='0'>満室</option><option value='-1'>電話</option>";
			    	}
			    }
				if($schedule == $options[$i])
				{
					$_strWeek .= "<option value=".$options[$i]." selected>".$options[$i]."室</option>";
				} 
				else
				{
					$_strWeek .= "<option value=".$options[$i]." >".$options[$i]."室</option>";
				}
			}
			$_strWeek .="</select></td>";	
    }
    
   	if($_dayRow[$_Month] != 31)
   {
  	  if($_dayRow[$_Month] == 30)
	  { 
		$_strWeek .= "<td align='center' valign='middle' bgcolor='#FFFFFF' class='text02'>&nbsp;</td>";
	  }
	 elseif($_dayRow[$_Month] == 29)
	  {
		$_strWeek .= "<td align='center' valign='middle' bgcolor='#FFFFFF' class='text02'>&nbsp;</td><td align='center' valign='middle' bgcolor='#FFFFFF' class='text02'>&nbsp;</td>";
	  }
	else
	 { 
			$_strWeek .= "<td align='center' valign='middle' bgcolor='#FFFFFF' class='text02'>&nbsp;</td><td align='center' valign='middle' bgcolor='#FFFFFF' class='text02'>&nbsp;</td>
			               <td align='center' valign='middle' bgcolor='#FFFFFF' class='text02'>&nbsp;</td>";
	 }
	}
	$_strWeek .=" </tr>
                                        </table></td>
                                        <td width='6' background='images/images/images/waku_06.gif'><img src='images/images/images/waku_06.gif' width='6' height='160' /></td>
                                      </tr>
                                      <tr>
                                        <td width='5'><img src='images/images/images/waku_07.gif' width='5' height='5' /></td>
                                        <td background='images/images/images/waku_08.gif'><img src='images/images/images/waku_08.gif' width='221' height='5' /></td>
                                        <td width='6'><img src='images/images/images/waku_09.gif' width='6' height='5' /></td>
                                      </tr>
                                  </table>
								  <input type='hidden' name='MonthDay' value='".$_dayRow[$_Month]."'/>
                                  <input type='hidden' name='Year' value='".$_Year."'/>
                                  <input type='hidden' name='month' value='".$_Month."'/>
								  </td>
                                  </tr>
                                  ";
	echo $_strYear.$_strWeek;
}
?>
